package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.service.AdminService;
import com.cskaoyan.market.db.admin.vo.DashboardVo;
import com.cskaoyan.market.db.domain.*;
import com.cskaoyan.market.db.mapper.*;
import com.cskaoyan.market.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

/**
 * @author TangHonghao
 * @since 2023/03/20 14:44
 */
public class AdminServiceImpl implements AdminService {
    @Override
    public DashboardVo dashBoard() {
        SqlSession sqlSession = MyBatisUtil.getSession();
        MarketUserMapper userMapper = sqlSession.getMapper(MarketUserMapper.class);
        long userTotal = userMapper.countByExample(new MarketUserExample());

        MarketGoodsMapper goodsMapper = sqlSession.getMapper(MarketGoodsMapper.class);
        long goodsTotal = goodsMapper.countByExample(new MarketGoodsExample());

        MarketGoodsProductMapper productMapper = sqlSession.getMapper(MarketGoodsProductMapper.class);
        long productTotal = productMapper.countByExample(new MarketGoodsProductExample());

        MarketOrderMapper orderMapper = sqlSession.getMapper(MarketOrderMapper.class);
        long orderTotal = orderMapper.countByExample(new MarketOrderExample());
        DashboardVo dbVo = new DashboardVo();
        dbVo.setGoodsTotal((int) goodsTotal);
        dbVo.setUserTotal((int) userTotal);
        dbVo.setProductTotal((int) productTotal);
        dbVo.setOrderTotal((int) orderTotal);

        return dbVo;
    }
}
